<template>
  <div class="app-container">
    <div>
      <el-form id="app" ref="form" :model="form" label-width="120px">
        <el-form-item label="项目名称" required>
          <el-input class="input-reader-name" v-model="form.project_name">
          </el-input>
        </el-form-item>
        <el-form-item label="负责人" required>
          <el-input class="input-reader-name" v-model="form.responsible_name">
          </el-input>
        </el-form-item>
        </el-form-item>
        <el-form-item label="测试人员" required>
          <el-input class="input-reader-name" v-model="form.test_user">
          </el-input>
        </el-form-item>
        <el-form-item label="开发人员" required>
          <el-input class="input-reader-name" v-model="form.dev_user">
          </el-input>
        </el-form-item>
        <el-form-item label="发布应用" required>
          <el-input class="input-reader-name" v-model="form.publish_app">
          </el-input>
        </el-form-item>
        <el-form-item label="简要描述">
          <el-input class="input-reader-name" v-model="form.simple_desc">
          </el-input>
        </el-form-item>
        <el-form-item label="其他信息">
          <el-input class="input-reader-name" v-model="form.other_desc">
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <br>
    <div style="text-align: center">
      <el-button type="success" @click="onSubmit">保存</el-button>
      <el-button @click="onCancel">取消</el-button>
    </div>
  </div>

</template>

<script>

import { createProject, updateProject, getProject } from '@/api/project/table'

export default {

  data() {
    return {
      editId: "",
      form: {
        project_name: '',
        responsible_name: '',
        dev_user: '',
        test_user: '',
        publish_app: '',
        simple_desc: '',
        other_desc: '',
      },
    }
  },
  mounted() {
    console.log(this.$route.query.id)
    this.editId = this.$route.query.id || "";
    if (this.editId) {
      this.getParams();
    }
  },
  methods: {
    onSubmit() {
      if (this.editId) {
        updateProject(this.form).then(response => {
        if (response.status == "000000") return
          this.$message.success('更新成功'),
            this.$router.replace(`/project/project_list`)
       })
      }
        else{
          createProject(this.form).then((response) => {
          console.log(response.msg);
          if (response.status == "000000") return
          this.$message.success('创建成功'),
            this.$router.replace(`/project/project_list`)
        })
      }
    },
    onCancel() {
      this.$confirm('此操作将退出编辑, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.replace(`/project/project_list`)
        this.$message({
          type: 'success',
          message: '退出成功!',
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消退出'
        })
      })
    },

    getParams() {
      var params = {}
      params['id'] = this.editId
      getProject(params).then(response => {
        this.form = response.data;
      })
    }
  }
}
</script>


<style scoped lang="scss">
.line {
  text-align: center;
}

.input-reader-name {
  width: 40%;
}

.flex-box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-content: center;

  .inline-box {
    display: inline-block;
    width: 350px;

    &:last-child {
      width: 500px;
    }
  }

  > span {
    font-size: 30px;
    line-height: 290px;
  }
}

</style>

